/**
 * @description
 * @author XIAJIUJIANG239
 * @createtime 2018/1/17
 */

// import Rx from 'rxjs/Rx'

const button = document.getElementById('test_btn')

Rx.Observable.fromEvent(button, 'click')
  .throttle(1000) // 至少隔一秒响应
  .map(event => event.clientX)
  /* 用scan隔离了count的状态 */
  .scan((count, clientX) => count + 1, 0)
  .subscribe((count_1, clientX) => console.log(`Clicked ${count_1} times!! clientX: ${clientX}`))



// observable 可观察对象

var observable = Rx.Observable.create(observer => {
  observer.next(1)
  observer.next(2)
  observer.next(3)

  setTimeout(() => {
    observer.next(4)
    // observer.complete()
  }, 1000)
})

console.log('just before subscribe..')
// observable.subscribe({
//   next: x => console.log('got value: ' + x),
//   error: err => console.error('error: '+ err),
//   complete: () => console.log('done.!'),
// })
observable.subscribe( x => {
  console.log('subscribe: ', x)
})
console.log('just after subscribe..')


